<template>
  <div class="table-slot-wrapper"
       @click="titleClick(slotData, {
          managerType: 'formAdmin',
          dataType: dataType
       })
    ">
    <span v-if="hasBeforeIcon" :class="['ico16', importantLevel, state, 'pre-icon']"></span>
    <span class="subject-text common-text">{{ slotData.subject }}</span>
    <span v-if="hasAfterIcon" :class="['ico16', hasAttsFlag, showAuthorityButton, bodyType]"></span>
  </div>
</template>

<script>
  import superviseMixin from '@/mixins/supervise/supervise-mixin.js';
  export default {
    name: 'SubjectTableRender',
    mixins: [superviseMixin],
    props: {
      slotData: {
        type: Object,
        default: () => {}
      }
    },
    computed: {
      importantLevel() {
        const { importantLevel } = this.slotData;
        if (importantLevel && importantLevel !== 1) {
          return `important${importantLevel}_16 `;
        }
        return ``;
      },
      hasAttsFlag() {
        const { hasAttsFlag } = this.slotData;
        if (hasAttsFlag) {
          return ` affix_16`;
        }
        return '';
      },
      showAuthorityButton() {
        const { showAuthorityButton } = this.slotData;
        if (showAuthorityButton) {
          return ` authorize_16`;
        }
        return '';
      },
      bodyType() {
        const { bodyType } = this.slotData;
        const list = ['', null, undefined, 10, 30, 90, '10', '30', '90'];
        if (!list.includes(bodyType)) {
          return ` office${bodyType}_16`;
        }
        return '';
      },
      state() {
        const { state } = this.slotData;
        if (state) {
          return ` flow${state}_16`;
        }
        return '';
      },
      hasAfterIcon() {
        const { hasAttsFlag, showAuthorityButton, bodyType } = this;
        return hasAttsFlag || showAuthorityButton || bodyType;
      },
      hasBeforeIcon() {
        const { importantLevel, state } = this;
        return importantLevel || state;
      }
    },
    methods: {
      opencollaboration(record) {
        let url =
          window._ctxPath +
          `/collaboration/collaboration.do?method=summary&summaryId=${record.summaryId}` +
          window.CsrfGuard.getUrlSurffix();
        window.openCtpWindow({ url: url });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .table-slot-wrapper {
    display: flex;
    align-items: center;
    width: 100%;
    .common-text {
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      word-break: break-word;
    }
    .ico16 {
      width: 16px;
      flex-shrink: 0;
    }
    .pre-icon {
      margin-right: 5px;
    }
  }
</style>
